#搜索业务 业务类
import time

import allure
from page.page_index import PageIndex
from page.page_searchResult import PageSerarchResult
from page.page_searchResultError import PageSearchResultError


class ServiceSearch(object):

    def __init__(self,driver,base_url):
        #初始化该业务有关的N个页面类对象
        self.page_index=PageIndex(driver,base_url)
        self.page_searchResult=PageSerarchResult(driver,base_url)
        self.page_searchResultError=PageSearchResultError(driver,base_url)


    def service_search_001(self,d):
        #完成首页
        allure.attach("","打开首页")
        self.page_index.openUrl()
        allure.attach("", f"输入搜索关键字{d['kw']}并回车")
        self.page_index.input_searchKwAndEnter(d["kw"])
        #完成搜索结果页
        time.sleep(2)
        imgName=self.page_searchResult.savePng3("搜索业务",d["key"]) #“搜索业务_K001_2024112909330”
        allure.attach(open(f'./screen/{imgName}.png', 'rb').read(), "搜索结果页面的截图",allure.attachment_type.PNG)
        return self.page_searchResult.isExists(d["yuqi"])

    def service_search_002(self,d):
        #完成首页
        self.page_index.openUrl()
        self.page_index.input_searchKwAndEnter(d["kw"])
        #完成搜索结果页
        siji=self.page_searchResultError.getErrorTipText()
        return d["yuqi"] in siji

    def service_search_003(self,d):
        #完成首页
        self.page_index.openUrl()
        self.page_index.input_searchKwAndEnter(d["kw"])
        #完成搜索结果页
        siji=self.page_searchResult.getErrorTip() #"对不起，没有找到相关商品"
        return d["yuqi"] in siji







